import service, {localStore} from "./axios";

let baseUrl = 'http://127.0.0.1:'

let rootUrl = 'https://apidong1.flypanda.org:8443'
function changeApiUrl(){
    return localStore.get("apiurl_list") != null ? localStore.get("apiurl_list")[0] : rootUrl
}
// 选择/切换连接模式
export function setModeCoreAPI(data) {
    return service({
        url:baseUrl+localStore.get("remotePort")+'/configs',
        method:'patch',
        data:data
    })
}
// 配置节点信息
export function setConfigNodeCoreAPI(data) {
    return service({
        url:baseUrl+localStore.get("remotePort")+'/configs',
        method:'put',
        data:data
    })
}
// 获取所有节点
export function getAllNodeCoreAPI() {
    return service({
        url:baseUrl+localStore.get("remotePort")+'/proxies',
        method:'get'
    })
}
// 选择/切换节点
export function changeNodeCoreAPI(url,data) {
    return service({
        url:baseUrl+localStore.get("remotePort")+'/proxies/'+url,
        method:'put',
        data:data
    })
}

// 登录
export function userLogin(data) {
    return service({
        url:changeApiUrl() + '/c_api/login',
        method:'post',
        data:data
    })
}
// 注册
export function registerUser(data) {
    return service({
        url:changeApiUrl() + '/c_api/register_token',
        method:'post',
        data:data
    })
}
// 退出登录
export function loginOut() {
    return service({
        url:changeApiUrl() + "/c_api/loginout?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
// 获取用户信息
export function getUserInfo(userId) {
    return service({
        url:changeApiUrl() + "/c_api/user/"+ userId + "?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
// 更新节点信息
export function getConfigNode(url) {
    return service({
        url:url,
        method:'get'
    })
}
// 检查token是否有效
export function checkUserToken() {
    return service({
        url:changeApiUrl() + "/c_api/check_token?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
// 获取返利金额和邀请码
export function getInviteInfo() {
    return service({
        url:changeApiUrl() + "/c_api/invite?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
// 获取返利列表
export function getInviteList(page) {
    return service({
        url:changeApiUrl() + "/c_api/payback?access_token=" +  localStore.get("access_token") + '&page=' + page,
        method:'get'
    })
}
// 获取购买记录列表
export function getBuyLogList(page) {
    return service({
        url:changeApiUrl() + "/c_api/buy_record?access_token=" +  localStore.get("access_token") + '&page=' + page,
        method:'get'
    })
}
// 获取商品列表
export function getShopList() {
    return service({
        url:changeApiUrl() + "/c_api/shop?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
// 获取商品支付二维码
export function getShopQRCode(data) {
    return service({
        url:changeApiUrl() + "/c_api/shop?access_token=" +  localStore.get("access_token"),
        method:'post',
        data:data
    })
}
// 余额支付
export function getYuePay(data) {
    return service({
        url:changeApiUrl() + "/c_api/balance_buy?access_token=" +  localStore.get("access_token"),
        method:'post',
        data:data
    })
}
// 提交工单
export function addticket(data) {
    return service({
        url:changeApiUrl() + "/c_api/addticket?access_token=" +  localStore.get("access_token"),
        method:'post',
        data:data
    })
}
// 工单列表
export function ticketlist(page,size) {
    return service({
        url:changeApiUrl() + "/c_api/ticketlist?access_token=" +  localStore.get("access_token") + '&page=' + page + "&page_num="+ size,
        method:'get'
    })
}
// 工单详情
export function ticketView(roodId) {
    return service({
        url:changeApiUrl() + "/c_api/ticket_view?access_token=" +  localStore.get("access_token") + '&root_id=' + roodId,
        method:'get'
    })
}
// 回复工单
export function updateTicket(data) {
    return service({
        url:changeApiUrl() + "/c_api/update_ticket?access_token=" +  localStore.get("access_token"),
        method:'post',
        data:data
    })
}
// 在线客服
export function onlineTicket() {
    return service({
        url:changeApiUrl() + "/c_api/online?access_token=" +  localStore.get("access_token"),
        method:'get'
    })
}
